package no.gnet.edvd.types;

import java.util.Iterator;
import java.util.List;

public class GenericEvent extends Event {

	private List<Option> options;
	private boolean privateEvent;
	private List<String> invitedList;
	public String league;

	@Override
	public List<Option> getOptions() {
		return options;
	}

	@Override
	public Option getOptionByName(String name) {
		List<Option> options = getOptions();
		for (Iterator<Option> iterator = options.iterator(); iterator.hasNext();) {
			Option option = (Option) iterator.next();
			if (option.name.equals(name))
				return option;
		}
		return null;
	}

	public void setOptions(List<Option> options) {
		this.options = options;
		_updateOptionsWithOwner();
	}

	private void _updateOptionsWithOwner() {
		if (options != null) {
			for (Iterator<Option> iterator = options.iterator(); iterator
					.hasNext();) {
				Option option = iterator.next();
				option.event = this;
			}
		}
	}

	@Override
	public String toString() {
		return "GenericEvent [options=" + (options!=null?options.size():0) + ", name=" + name + ", description=" + description + ", category="
				+ category + ", private=" + privateEvent +", betDeadline=" + betDeadline + ", eventDecidedTime=" + eventDecidedTime
				+ ", eventPosted=" + eventPosted + ", owner=" + owner + ", eventType=" + eventType + ", likes=" + likes
				+ ", likers=" + likers + ", state=" + state + ", winningOption=" + (winningOption != null) + ", id=" + id + "]";
	}

	public boolean isPrivateEvent() {
		return privateEvent;
	}

	public void setPrivateEvent(boolean privateEvent) {
		this.privateEvent = privateEvent;
	}
	
	@Override
	public List<String> getInvitedList() {
		return invitedList;
	}

	public void setInvitedList(List<String> invitedList) {
		this.invitedList = invitedList;
	}

	@Override
	public boolean isPrivate() {
		return privateEvent;
	}

//	@Override
//	public String toString() {
//		return "GenericEvent [options=" + Arrays.toString(options.toArray()) + "]";
//	}

}
